﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Business;
using System.Web.Security;
public partial class admin_DeatilView_Workorder : System.Web.UI.Page
{
    int workorderID;
    string machinename;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack){
        workorderID = Int32.Parse(Request.QueryString["workorder_id"]);
        machinename =(string) Request.QueryString["machinename"];
        CreateConn obj = new CreateConn();
        string query = "SELECT workorder_reference_no,machine_id,"
            + "description,date_submitted,status FROM WorkOrders" +
            " WHERE workorder_id='" + workorderID+"'";
        DataTable dt = obj.SQLConnDataTable(query);
        foreach(DataRow dr in dt.Rows){
            String referNo = dr["workorder_reference_no"].ToString();
            Session["referNo"] = referNo;
            //int machine_id = Int32.Parse(dr["machine_id"].ToString());
            String description = dr["description"].ToString();
            string status = dr["status"].ToString();
            String date_submitted = dr["date_submitted"].ToString();
            workorderTextbox.Text = referNo;
            MachineName_tb.Text = machinename;
            Detail_tb.Text = description;
            dateRecorded_tb.Text = date_submitted;
            if(status.Equals("0")){
                status_dropdownlist.SelectedIndex = 1;

            }
            else{
                status_dropdownlist.SelectedIndex = 0;

            }
        
        }}
    }
    protected void updatebutton_clicked(Object sender, EventArgs e)
    {
        CreateConn obj = new CreateConn();
        string status;
        string datesubmit = dateRecorded_tb.Text;
        string detail = Detail_tb.Text;
        if (status_dropdownlist.SelectedIndex==1)
        {
            status = "1";
        }
        else
        {
            status = "0";
        }
        string referNo = (String)Session["referNo"];
        string referNo2 = workorderTextbox.Text;
        String query = "UPDATE WorkOrders SET status='"+status+"' and workorder_reference_no='"+referNo2
            +"'and date_submitted=convert(datetime,'"+datesubmit+"',103) and description='"+detail+"' WHERE workorder_id='"+workorderID;
        obj.SQLConnDataTable(query);
        //statusCheckbox.Enabled = false;
        check_editButton.Visible = true;
        check_updatebutton.Visible = false;
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Server.Transfer("SearchResults.aspx");
    }
    protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
    {


        Session.Contents.Remove("UserDetails");
        Session.Abandon();
        Session.Contents.RemoveAll();
        FormsAuthentication.SignOut();
        Response.Redirect("../Default.aspx");
    }
}
